import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;


public class DS_CSV implements IDS 
{
	private String fName = "zzzz";
	
	public DS_CSV( String fName )
	{
		this.fName = fName;
	}

	@Override
	public void Save(List<Person> pp) 
	{
		try 
		{
			PrintWriter pw = new PrintWriter( new FileOutputStream(fName) );
			for(Person p: pp)
			{
				pw.println( p );
			}
			pw.close();	
		} 
		catch (FileNotFoundException e) 
		{
			e.printStackTrace();
		}		
	}

	@Override
	public List<Person> Load() 
	{
		List<Person> lst = new ArrayList<Person>();
		try 
		{
			Scanner scanner = new Scanner(new File(fName) );
			while( scanner.hasNextLine() )
			{
				String str = scanner.nextLine();
				Person p = new Person();
				p.fromString(str);
				lst.add(p);
			}
			scanner.close();
		} 
		catch (FileNotFoundException e) 
		{
			e.printStackTrace();
		}		
		return lst;
	}

}
